package com.ybzl;

import com.ybzl.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/test/redis")
public class Tcontroller {

    @Autowired
    private RedisCache redisCache;


    @RequestMapping("/add")
    public void add(){

        Map<String,Object> userIndo = new HashMap<>();
        userIndo.put("name","张三");
        userIndo.put("age","20");

        redisCache.setCacheObject("user:token",userIndo);

    }


    /**
     * 模拟测试工具上显示的TTL单位是秒
     */
    @RequestMapping("/add/time")
    public void addTime(){
        Map<String,Object> userIndo = new HashMap<>();
        userIndo.put("name","李四");
        userIndo.put("age","21");

        //redisCache.setCacheObject("user:token",userIndo,1, TimeUnit.MINUTES);
        //redisCache.setCacheObject("user:token",userIndo,60, TimeUnit.SECONDS);
        redisCache.setCacheObject("user:token",userIndo,1, TimeUnit.HOURS);

    }

}
